using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;

//Service Route: Copy to 'Global.asax'
//  RouteTable.Routes.Add(new ServiceRoute("Empresas", new WebServiceHostFactory(), typeof(EmpresasService)));
//
namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class EmpresasService : BaseService
    {
        [WebInvoke(UriTemplate = "Create", Method = "POST")]
        public bool Create(Empresas Empresa)
        {
            Provider.AddToEmpresas(Empresa);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "GetAll", Method = "POST")]
        public ArrayList GetAll()
        {
            return new ArrayList(Provider.Empresas.ToList());
        }

        [WebInvoke(UriTemplate = "GetById", Method = "POST")]
        public Empresas GetById(string Id)
        {
            return Provider.Empresas.First(i => i.NitEmpresa == Id);
        }

        [WebInvoke(UriTemplate = "Update", Method = "POST")]
        public bool Update(Empresas Empresa)
        {
            Empresas miEmprea = Provider.Empresas.Where(t => t.NitEmpresa == Empresa.NitEmpresa).First();
            miEmprea.Copy(Empresa);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "Delete", Method = "POST")]
        public bool Delete(string IdEmpresa)
        {
            Provider.Empresas.DeleteObject(Provider.Empresas.Where(t => t.NitEmpresa == IdEmpresa).First());
            return Provider.TrySaveChanges();
        }

    }
}